﻿using System;
using System.Data.SqlClient;
using System.Collections.Generic;

/**
 * Trace object holds fields for all data contained in each incoming GPS trace
 */
public class Trace
{
    public int offender { get; set; }
    public DateTime time { get; set; }
    public Double lon { get; set; }
    public Double lat { get; set; }
    public Double direction { get; set; }

    public Trace()
    {

    }

    public Trace(int poffender, DateTime ptime, double plon, double plat, double pdirection)
    {
        offender = poffender;
        time = ptime;
        lon = plon;
        lat = plat;
        direction = pdirection;
    }

    //public SqlCommand restrictedZone()
    //{
    //    SqlCommand myCommand = new SqlCommand(  "SELECT locationID, latitude1, longitude1, latitude2, longitude2 " +
    //                                            "FROM   location " +
    //                                            "WHERE  @latitude < location.latitude1 " +
    //                                            "AND    @latitude > location.latitude2 " +
    //                                            "AND    @longitude > location.longitude1 " +
    //                                            "AND    @longitude < location.longitude2 ");
    //    myCommand.Parameters.AddWithValue("@latitude", lat);
    //    myCommand.Parameters.AddWithValue("@longitude", lon);
    //    return myCommand;
    //}


    /**
     * HistoryTableInsert()
     *  Returns a SqlCommand configured to insert its own fields into the history table
     */
    public SqlCommand historyTableInsert()
    {
        // debug -- open database connection and write test gps traces to db TESTLOG table
        SqlCommand myCommand = new SqlCommand(  "INSERT into history (offenderID, latitude, longitude, date_time, direction) " +
                                                "VALUES (@offenderID, @latitude, @longitude, @date_time, @direction) ");
        myCommand.Parameters.AddWithValue("@offenderID", offender);
        myCommand.Parameters.AddWithValue("@latitude", lat);
        myCommand.Parameters.AddWithValue("@longitude", lon);
        myCommand.Parameters.AddWithValue("@date_time", time);
        myCommand.Parameters.AddWithValue("@direction", direction);
        return myCommand;
    }

    /**
     * ToString() override -- outputs JSON formatted string
     */
    public override String ToString()
    {
        String jsonString = "{\"time\":\"" + time +
                            "\",\"lon\":\"" + lon +
                            "\",\"lat\":\"" + lat + "\"}";
        return jsonString;
    }
}

public class OffenderJSON
{
    public List<Offenders> Offenders { get; set; }

    public OffenderJSON(List<Offenders> offs)
    {
        Offenders = offs;
    }
}

public class Offenders
{
    //public Offender[] Offender { get; set; }
    public List<Offender> Offender { get; set; }

    public Offenders(List<Offender> offs)
    {
        Offender = offs;
    }

    public Offenders()
    {

    }

}

public class Offender
{
    public int OID { get; set; }
    //public Location[] Location { get; set; }

    public List<Location> Location { get; set; }

    public Offender(int offid, List<Location> loc)
    {
        OID = offid;
        Location = loc;
    }

    public Offender()
    {

    }
}

//public class Offender
//{
//    public OIDs OID { get; set; }
//    //public Location[] Location { get; set; }

//    public Locations Locations { get; set; }

//    public Offender(OIDs id, Locations locs)
//    {
//        OID = id;
//        Locations = locs;
//    }

//    public Offender()
//    {

//    }
//}

//public class Locations
//{
//    public List<Location> Location;

//    public Locations(List<Location> locs)
//    {
//        Location = locs;
//    }
//}

//public class OIDs
//{
//    public int OID { get; set; }

//    public OIDs(int id)
//    {
//        OID = id;
//    }
//}

public class Location
{
    public DateTime TimeStamp { get; set; }
    public double Lat { get; set; }
    public double Lon { get; set; }

    public Location(DateTime time, double latitude, double longitude)
    {
        TimeStamp = time;
        Lat = latitude;
        Lon = longitude;
    }

    public Location()
    {

    }

}

public class AlertsJSON
{
    public List<Alerts> Alerts;

    public AlertsJSON(List<Alerts> als)
    {
        Alerts = als;
    }

}

public class Alerts
{
    public int Number { get; set; }
    public DateTime TimeStamp { get; set; }
    public string AlertTitle { get; set; }
    public string Message { get; set; }
    public string Status { get; set; }
    public string Event { get; set; }
    public int Location { get; set; }
    public List<OID_Involved> OID_Involved { get; set; }

    public Alerts(int num, DateTime time, string title, string mess, string stat, string eventType, int loc, List<OID_Involved> oids)
    {
        Number = num;
        TimeStamp = time;
        AlertTitle = title;
        Message = mess;
        Status = stat;
        Event = eventType;
        Location = loc;
        OID_Involved = oids;
    }

    public Alerts()
    {

    }
}

public class OID_Involved
{
    public int OID { get; set; }
    public double Lat { get; set; }
    public double Lon { get; set; }
    public double Bearing { get; set; }

    public OID_Involved(int offid, double latitude, double longitude)
    {
        OID = offid;
        Lat = latitude;
        Lon = longitude;
        Bearing = 0.00;
    }

    public OID_Involved()
    {

    }
}


//public class Alert
//{
//    //public int eventTypeID { get; set; }
//    //public int offenderID { get; set; }
//    //public Double lon { get; set; }
//    //public Double lat { get; set; }

//    public int number { get; set; }
//    public DateTime timestamp { get; set; }
//    public string title { get; set; }
//    public string message { get; set; }
//    public string eventType { get; set; }
//    public int location { get; set; }
//    public 

//    public Alert(int alertID, DateTime )
//    {

//    }

//    //public Alert(int peventTypeID, int poffenderID, double plon, double plat)
//    //{
//    //    eventTypeID = peventTypeID;
//    //    offenderID = poffenderID;
//    //    lon = plon;
//    //    lat = plat;
//    //}

//    //public SqlCommand eventLogInsert()
//    //{
//    //    // debug -- open database connection and write test gps traces to db TESTLOG table
//    //    SqlCommand myCommand = new SqlCommand("INSERT into eventLog (eventTypeID, offenderID, latitude, longitude, direction) " +
//    //                                            "VALUES (@eventTypeID, @offenderID, @latitude, @longitude, @direction) ");
//    //    myCommand.Parameters.AddWithValue("@eventTypeID", eventTypeID);
//    //    myCommand.Parameters.AddWithValue("@offenderID", offenderID);
//    //    myCommand.Parameters.AddWithValue("@latitude", lat);
//    //    myCommand.Parameters.AddWithValue("@longitude", lon);
//    //    myCommand.Parameters.AddWithValue("@direction", 0.00);
//    //    return myCommand;
//    //}
//}